package me.sensen;
import me.sensen.commandfunction.CommandFunction;
import me.sensen.commands.SetLocal;
import me.sensen.commands.SetUPan;

import javax.swing.*;

/**
 * @author Sensen
 */
public class Main {

    public static String localPath = "";
    public static String UPanPath = "";

    public static void main(String[] args) {
        try {
            String runtimePath = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath().substring(1);
            if(args.length == 0) {
                if(runtimePath.endsWith(".jar")) {
                    Runtime.getRuntime().exec("cmd /c start cmd /k java -jar " + runtimePath + " run");
                    return;
                }
            }
        } catch (Exception ignored) {
        }

        startCommand();
    }

    public static void start() {
        SwingUtilities.invokeLater(() -> {
            Services frame = new Services();
            frame.setVisible(true);
        });
    }

    public static void startCommand() {
        CommandFunction.startCommandFunction();
        System.out.println("Use /setLocal or /setUPan to set your path");
        CommandFunction.registerCommand("setLocal", new SetLocal());
        CommandFunction.registerCommand("setUPan", new SetUPan());
    }

    public static void checkPath() {
        if (!localPath.isEmpty() && !UPanPath.isEmpty()) {
            start();
            CommandFunction.stopCommandFunction();
            System.out.println("UI has appeared, command function shut down.");
        }
    }
}